package com.hdw.med.controller;

import com.hdw.common.base.BaseException;
import com.hdw.common.base.BaseResult;
import com.hdw.common.constant.CommonResultConstant;
import com.hdw.common.vo.PaginationVO;
import com.hdw.med.api.MdMedOdsDwFidService;
import com.hdw.med.bean.model.MdMedOdsDwFid;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * mdMedOdsDwFid控制器
 * Created by eleven on 2021/11/29.
 */
@RestController
@RequestMapping("/hoze/mdMedOdsDwFid/")
@Api(description = "开发中", tags = "开发中")
@CrossOrigin(origins = "*", maxAge = 3600)
public class MdMedOdsDwFidController {

    @Autowired
    MdMedOdsDwFidService mdMedOdsDwFidService;

    @ApiOperation(value = "分页查询")
    @RequestMapping(value = "findByPage", method = RequestMethod.POST)
    public BaseResult findByPage(@RequestBody MdMedOdsDwFid mdMedOdsDwFid, Integer pageNum, Integer pageSize) {
        PaginationVO<MdMedOdsDwFid> pageVO = mdMedOdsDwFidService.findPageByModel(mdMedOdsDwFid, pageNum, pageSize);
        return new BaseResult(CommonResultConstant.SUCCESS, pageVO);
    }

    @ApiOperation(value = "保存")
    @ApiImplicitParam(name = "mdMedOdsDwFid", value = "实体", paramType = "body", required = true, dataType = "MdMedOdsDwFid")
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public BaseResult insert(@RequestBody MdMedOdsDwFid mdMedOdsDwFid, HttpServletRequest request) {
        int num = mdMedOdsDwFidService.insertSelective(mdMedOdsDwFid);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }

    @ApiOperation(value = "详情")
    @ApiImplicitParam(name = "idOdsDwFid", value = "主键", paramType = "query", required = true, dataType = "String")
    @RequestMapping(value = "getById", method = RequestMethod.GET)
    public BaseResult getById(Long idOdsDwFid, HttpServletRequest request) throws BaseException {
        if (idOdsDwFid == null) {
            throw new BaseException("请选择要编辑的项");
        }
        MdMedOdsDwFid mdMedOdsDwFid = mdMedOdsDwFidService.getById(idOdsDwFid);
        return new BaseResult(CommonResultConstant.SUCCESS, mdMedOdsDwFid);
    }

    @ApiOperation(value = "修改")
    @ApiImplicitParam(name = "mdMedOdsDwFid", value = "实体", paramType = "body", required = true, dataType = "MdMedOdsDwFid")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public BaseResult update(@RequestBody MdMedOdsDwFid mdMedOdsDwFid, HttpServletRequest request) {
        int num = mdMedOdsDwFidService.updateByIdSelective(mdMedOdsDwFid);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }

    @ApiOperation(value = "根据主键删除")
    @ApiImplicitParam(name = "idOdsDwFid", value = "主键", paramType = "query", required = true, dataType = "String")
    @RequestMapping(value = "delete", method = RequestMethod.GET)
    public BaseResult delete(Long idOdsDwFid, HttpServletRequest request) throws BaseException {
        if (idOdsDwFid == null) {
            throw new BaseException("请选择要删除的项");
        }
        int num = mdMedOdsDwFidService.deleteById(idOdsDwFid);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }
}
